package com.leon.alishop.spider.config;

import java.io.IOException;
import java.util.Properties;

public class SpiderProperties {

	private static final String file = "alishop-spider.properties";
	
	private static final String CRAWL_DEFAULT_SLEEP_TIME = "spider.crawlDefaultSleepTime";
	
	private static final String CRAWL_FILE_RETRY_TIME = "spider.crawlFailRetryTime";
	
	private static final String ALIBABA_HOME_URL = "spider.alibabaStoreHomeUrl";
	
	private static Properties properties;
	
	static{
		properties = new Properties();
		try {
			properties.load(SpiderProperties.class.getClassLoader().getResourceAsStream(file));
		} catch (IOException e) {
		}
	}
	
	public static long getCrawlDefaultSleepTime(){
		try {
			Long.valueOf(properties.getProperty(CRAWL_DEFAULT_SLEEP_TIME));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 1000;
	}
	
	public static int getCrawlFailRetryTime(){
		try {
			Long.valueOf(properties.getProperty(CRAWL_FILE_RETRY_TIME));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 5;
	}
	
	public static String getAlibabaStoreHomeUrl(){
		return properties.getProperty(ALIBABA_HOME_URL);
	}
	
}
